// ES2020的语法

type Person = {
  name:string,
  friend?:{
    name:string,
    age?:number
  }
}


const info:Person = {
  name:'why',
  friend:{
    name:'chan',
  }
}

const info1:Person = {
  name:'why',
}
console.log(info.name); 
// console.log(info.friend.name);   //报错
// console.log(info.friend!.name);   //  非空类型断言
console.log(info.friend?.name);   //可选
console.log(info.friend?.age);   //可选
console.log(info1.friend?.name);    //undefined